// This is a manifest file that'll be compiled into including all the files listed below.
// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
// be included in the compiled file accessible from http://example.com/assets/application.js
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
//= require jquery
//= require jquery_ujs
//= require jquery-ui



window.Ht = {};

(function (Ht) {

    wattingBtnConfig = {};
    wattingBtnConfig.btn_value = {};
    wattingBtnConfig.clas_name = {};
    wattingBtnConfig.bg_img = {};
    wattingBtnConfig.css_set = {};
    wattingBtnConfig.oTarget = {};
    wattingBtnConfig.clk_handler = {};
    wattingBtnConfig.lk_href = {};
    wattingBtnConfig.ele = {};
    wattingBtnConfig.subNode = {};
    /* the waiting for query
     @author :Wxl
     @modification history :2012-03-14
     @see : The style of the waiting can be found in application.css, you can use the
     method in your query method where you want to show the waiting message
     @argument id :[String]  The id of the button
     @argument txt :[String]  The waiting message
     @return :Null
     @exception :Null
     @example:
     //临时禁用查询按钮，显示等待信息
     Ht.waitingBtn("s-btn","查询中");
     */
    Ht.waitingBtn = function (id, txt) {

        wattingBtnConfig.oTarget[id] = document.getElementById(id);
        wattingBtnConfig.clk_handler[id] = wattingBtnConfig.oTarget[id].onclick;
        wattingBtnConfig.oTarget[id].onclick = null;

        wattingBtnConfig.lk_href[id] = wattingBtnConfig.oTarget[id].getAttribute("href");
        wattingBtnConfig.btn_value[id] = wattingBtnConfig.oTarget[id].text;
        wattingBtnConfig.clas_name[id] = wattingBtnConfig.oTarget[id].className;
        wattingBtnConfig.bg_img[id] = wattingBtnConfig.oTarget[id].style.backgroundImage;
        wattingBtnConfig.css_set[id] = $(wattingBtnConfig.oTarget[id]).css;


        wattingBtnConfig.oTarget[id].className += " waiting";
        var waitingTxt = $("<span/>");
        waitingTxt.text(txt);
        waitingTxt.css({"float": "left"});
        $(wattingBtnConfig.oTarget[id]).text("");
        wattingBtnConfig.oTarget[id].href = "javascript:void(0);";

//        wattingBtnConfig.subNode[id] = $("<img></img>");
//      var wid = wattingBtnConfig.oTarget[id].clientWidth.toString();
//      var hig = wattingBtnConfig.oTarget[id].clientHeight.toString();
        var wid = $(wattingBtnConfig.oTarget[id]).outerWidth().toString();
        var hig = $(wattingBtnConfig.oTarget[id]).outerWidth().toString();
//        if ((navigator.appName == "Microsoft Internet Explorer") && (parseFloat(navigator.appVersion) <= 6))
//            wattingBtnConfig.subNode[id].css({"right":"0px", "position":"absolute", "width":wid + "px", "height":hig + "px", "background-image":"url(/assets/loading.gif)", "background-position":"5px 0px", "background-repeat":"no-repeat"})
//        else
//            wattingBtnConfig.subNode[id].css({"right":"0px", "position":"absolute", "width":wid + "px", "height":hig + "px", "background-image":"url(/assets/loading.gif)", "background-position":"5px 5px", "background-repeat":"no-repeat"})
        wattingBtnConfig.subNode[id] = $("<img src='/assets/loading.gif' class='inline-block' style='margin-top: 2px'/>");
        $(wattingBtnConfig.oTarget[id]).append(waitingTxt);
        $(wattingBtnConfig.oTarget[id]).append(wattingBtnConfig.subNode[id]);
    }
    /* the stopWaiting for query
     @author :Wxl
     @modification history :2012-03-14
     @see : The style of the waiting can be found in application.css, you can use the
     method in your query method where you want to clear the waiting message
     @argument: id:[String] the id of the button
     @return :Null
     @exception :Null
     @example:
     //重新启用查询按钮，清除等待信息
     Ht.stopWaiting("s-btn");
     */
    Ht.stopWaiting = function (id) {
        wattingBtnConfig.oTarget[id].href = wattingBtnConfig.lk_href[id];
//        if ((navigator.userAgent.indexOf("360SE") > 0) || (navigator.appName == "Microsoft Internet Explorer") && (parseFloat(navigator.appVersion) <= 6)) {
            $(wattingBtnConfig.oTarget[id]).text("  查询");
//        }
        $(wattingBtnConfig.oTarget[id]).text(wattingBtnConfig.btn_value[id]);
        wattingBtnConfig.oTarget[id].className = wattingBtnConfig.clas_name[id];
        wattingBtnConfig.oTarget[id].style.backgroundImage = wattingBtnConfig.bg_img[id];
        $(wattingBtnConfig.oTarget[id]).css = wattingBtnConfig.css_set[id];
        wattingBtnConfig.oTarget[id].onclick = wattingBtnConfig.clk_handler[id];
        wattingBtnConfig.subNode[id].remove();
    }

})(Ht);
/* the tip for input
 @author :Wxl
 @modification history :2012-03-12
 @see :The style of the inputTip can be found in application.css
 @argument id :String  The id of the input
 @argument txt :String  The tip for the input
 @return :Null
 @exception :Null
 */

Ht.inputTip = function (id, txt) {
    var input = document.getElementById(id);
    // 需判断input是否为null
    if (input) {
        input.className += " input-tip";
        input.value = txt;
        if (input.value == "") {
            input.value = txt;
        }
        $(input).focus(function () {
            if (input.value == txt) {
                input.value = "";
            }
        });
        $(input).blur(function () {
            if (input.value == "") {
                input.value = txt;
            }
        });
    }
};

//隐藏下拉框，仅针对IE6下遮盖物无法遮盖下拉框的情况。
/*@author :Wxl
 @modification history :2012-03-24
 @see : 将visibility：hidden和display：none分别处理，保留其原来的占位状态，关于遮盖物参见motor_cate_maps.js
 @argument ：
 @return :Null
 @exception :Null
 @use: 每次调用均会切换当前页面内所有下拉框的显示与隐藏状态
 */
Ht.toogleSelect = function () {
    if ((navigator.appName == "Microsoft Internet Explorer") && (navigator.appVersion.split(";")[1].replace(/[ ]/g, "") == "MSIE6.0")) {

        var $select = $("select");

        $select.each(function (index, item) {

            if ($(item).css("visibility") == "hidden")
                $(item).css("visibility", "visible");
            else if ($(item).css("display") == "none")
                $(item).css("display", "block");
            else if ($(item).css("display") == "block")
                $(item).css("display", "none");
            else
                $(item).css("visibility", "hidden");
        });
    }
}


$(document).ready(function () {
    grid_init();

    var notice_div = $("#notice");
    if (notice_div.html() != '') {
        show_notice(notice_div.html());
    }
    if (navigator.userAgent.indexOf("360SE") > 0) {
//        alert(navigator.appName + "\n"+ navigator.appVersion + "\n" + navigator.userAgent)
        $(".toggle-btns-wrap .toggle-btn:nth-child(" + "2" + ")").css({"marginTop":"5px"});
        $(".block-nav ul").css({"paddingLeft":"0px"});
        $(".block-nav h2").css({"fontSize":"10pt"});
    }
//    使用IE滤镜解决IE6下PNG图片灰背景的问题 correctPNG();

    //if (navigator.userAgent.indexOf("360SE") > 0) {
    //    alert("4")
    //}

//    $(document).scroll(function() {  // OR  $(window).scroll(function() {
//        didScroll = true;
//    });
//    to
//
//    $('div#page').scroll(function() {
//        didScroll = true;
//    });

});

function grid_init() {
    $(".grid tr").mouseover(
        function () {
            $(this).addClass("over");
        }).mouseout(function () {
            $(this).removeClass("over");
        });
    $(".grid tr:even").addClass("alt");
}

/**
 * 显示信息提示栏
 */
function show_notice(notice_str) {
    var notice_div = $("#notice");
    notice_div.html(notice_str);

    if (notice_div.html() != '') {
        notice_div.show();
    }
    var last_position = 0.5 * (0.618 * $(window).height() - notice_div.height()) + $(document).scrollTop();
    notice_div.css("top", last_position + 150);
    notice_div.css("left", ($(".fake-body").width() - notice_div.width()) / 2);
    notice_div.animate({top:last_position }, 200, null, function () {
        window.setTimeout(function () {
            notice_div.fadeOut(1000, function () {
                notice_div.html("");
            });
        }, 2000);
    });
}

/**
 * 显示遮蔽物,遮蔽物上的提示信息
 */
function show_shelter(msg) {
    if (msg == null ||  msg  == undefined) {
        msg = "正在查询，请稍后...";
    }
//    console.log($("#shelter_msg"));
    $("#shelter_msg").html(msg);
    $(".shelter_pic").show();
    resize_shelter();
    $(".shelter").show();
    $(".shelter").css("background", "#000");
    $(".shelter").fadeTo(0, 0.25);

}
/**
 * 隐藏遮蔽物
 */
function hide_shelter() {
    $(".shelter-pic").hide();
    $(".shelter").hide();
}

/**
 * 改变遮蔽物的大小
 */
function resize_shelter() {
    var width = $("#mapC").width();
    var height = $("#mapC").height() ;;
    $(".shelter").width(width);
    $(".shelter").height(height);
    $(".shelter").css("top", 0);
    $(".shelter").css("left", 0);
}




// 对Date的扩展，将 Date 转化为指定格式的String
// 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符，
// 年(y)可以用 1-4 个占位符，毫秒(S)只能用 1 个占位符(是 1-3 位的数字)
// 例子：
// (new Date()).format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423
// (new Date()).format("yyyy-M-d h:m:s.S")      ==> 2006-7-2 8:9:4.18
Date.prototype.format = function(fmt)
{
    var o = {
        "M+" : this.getMonth()+1,                 //月份
        "d+" : this.getDate(),                    //日
        "h+" : this.getHours(),                   //小时
        "m+" : this.getMinutes(),                 //分
        "s+" : this.getSeconds(),                 //秒
        "q+" : Math.floor((this.getMonth()+3)/3), //季度
        "S"  : this.getMilliseconds()             //毫秒
    };
    if(/(y+)/.test(fmt))
        fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
    for(var k in o)
        if(new RegExp("("+ k +")").test(fmt))
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
    return fmt;
}

